package work.xiaohong.gupiao.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import work.xiaohong.gupiao.pojo.*;
import work.xiaohong.gupiao.pojo.*;
import work.xiaohong.gupiao.service.JijinFreeNumberService;
import work.xiaohong.gupiao.service.JijinService;
import work.xiaohong.gupiao.time.HttpUtil;
import work.xiaohong.gupiao.time.JijinHttpUtil;
import work.xiaohong.gupiao.util.JijinUrlUtil;
import work.xiaohong.gupiao.util.UrlUtil;
import entity.Result;
import entity.StatusCode;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;

@Tag(name = "Jijin接口文档")
@RestController
@RequestMapping("/jijin")
//@CrossOrigin
public class JijinController {

    @Autowired
    private JijinService jijinService;

    @Autowired
    private JijinFreeNumberService jijinFreeNumberService;
    
    private static Set<String> mySet = new HashSet<String>();


    public static void main(String[] args) {

    }

    // 获得当前时间多少天后的日期
    public static String getDay(Integer days){
        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_MONTH, days);
        Date result = (Date) calendar.getTime();
        return format.format(result);
    }

    /***
     * 分页条件搜索实现Jijin
     * @param jijin
     * @param page
     * @param size
     * @return
     */
    @Operation(summary = "条件分页查询Jijin",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @Parameters({
            @Parameter(in = ParameterIn.PATH, name = "page", description = "当前页", required = true),
            @Parameter(in = ParameterIn.PATH, name = "size", description = "每页显示条数", required = true)
    })
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<Page> findPage(@RequestBody(required = false) @Parameter(name = "Jijin对象",required = true) Jijin jijin, @PathVariable int page, @PathVariable  int size){
        //调用JijinService实现分页条件查询Jijin
        Page pageInfo = jijinService.findPage(jijin, page, size);
        return new Result<Page>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 分页搜索实现Jijin
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @Operation(summary = "分页查询Jijin",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @Parameters({
            @Parameter(in = ParameterIn.PATH, name = "page", description = "当前页", required = true),
            @Parameter(in = ParameterIn.PATH, name = "size", description = "每页显示条数", required = true)
    })
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<Page> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用JijinService实现分页查询Jijin
        Page pageInfo = jijinService.findPage(page, size);
        return new Result<Page>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索Jijin数据
     * @param jijin
     * @return
     */
    @Operation(summary = "多条件查询Jijin",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @PostMapping(value = "/search" )
    public Result<List<Jijin>> findList(@RequestBody(required = false) @Parameter(name = "Jijin对象",required = true) Jijin jijin){
        //调用JijinService实现条件查询Jijin
        List<Jijin> list = jijinService.findList(jijin);
        return new Result<List<Jijin>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据Id删除jijin数据
     * @param id
     * @return
     */
    @Operation(summary = "根据ID删除Jijin",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @Parameter(in = ParameterIn.PATH, name = "id", description = "ID", required = true)
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable Integer id){
        //调用JijinService实现根据ID删除
        jijinService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 根据ID修改Jijin数据
     * @param jijin
     * @param id
     * @return
     */
    @Operation(summary = "根据ID修改Jijin",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @Parameter(in = ParameterIn.PATH, name = "id", description = "ID", required = true)
    @PutMapping(value = "/{id}" )
    public Result update(@RequestBody @Parameter(name = "Jijin对象",required = true) Jijin jijin,@PathVariable Integer id){
        // 补充id
        jijin.setId(id);
        //调用JijinService实现修改Jijin
        jijinService.update(jijin);
        return new Result(true,StatusCode.OK,"修改成功");
    }


    /***
     * 卖出基金
     * @param id
     * @return
     */
    @Operation(summary = "卖出基金",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @Parameter(in = ParameterIn.PATH, name = "id", description = "ID", required = true)
    @PutMapping(value = "/sell/{id}" )
    public Result sell(@PathVariable Integer id){
        try {
            Jijin jijin = new Jijin();
            // 补充id
            jijin.setId(id);
            // 补充参数
            jijin.setStatus(3);
            //调用JijinService实现修改Jijin
            jijinService.update(jijin);
            // 可赎份额更新
            JijinFreeNumber seletJijinFreeNumber = new JijinFreeNumber();
            seletJijinFreeNumber.setCode(jijinService.findById(id).getCode());
            List<JijinFreeNumber> freeList = jijinFreeNumberService.findList(seletJijinFreeNumber);
            if (freeList != null && freeList.size() > 0){
                JijinFreeNumber jijinFreeNumber = freeList.get(0);
                String buyNumber = jijinService.findById(id).getBuyNumber();
                jijinFreeNumber.setFreeNumber((Float.valueOf(jijinFreeNumber.getFreeNumber())-Float.valueOf(buyNumber))+"");
                jijinFreeNumberService.update(jijinFreeNumber);
            }
            return new Result(true,StatusCode.OK,"卖出成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true,StatusCode.ERROR,"卖出失败");
        }

    }


    /***
     * 撤回卖出
     * @param id
     * @return
     */
    @Operation(summary = "卖出基金",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @Parameter(in = ParameterIn.PATH, name = "id", description = "ID", required = true)
    @PutMapping(value = "/recall/{id}" )
    public Result recall(@PathVariable Integer id){
        try {
            Jijin jijin = new Jijin();
            // 补充id
            jijin.setId(id);
            // 补充参数
            jijin.setStatus(1);
            //调用JijinService实现修改Jijin
            jijinService.update(jijin);
            // 可赎份额更新
            JijinFreeNumber seletJijinFreeNumber = new JijinFreeNumber();
            seletJijinFreeNumber.setCode(jijinService.findById(id).getCode());
            List<JijinFreeNumber> freeList = jijinFreeNumberService.findList(seletJijinFreeNumber);
            if (freeList != null && freeList.size() > 0){
                JijinFreeNumber jijinFreeNumber = freeList.get(0);
                String buyNumber = jijinService.findById(id).getBuyNumber();
                jijinFreeNumber.setFreeNumber((Float.valueOf(jijinFreeNumber.getFreeNumber())+Float.valueOf(buyNumber))+"");
                jijinFreeNumberService.update(jijinFreeNumber);
            }
            return new Result(true,StatusCode.OK,"撤回卖出成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true,StatusCode.ERROR,"撤回卖出失败");
        }

    }


    /***
     * 新增Jijin数据
     * @param jijin
     * @return
     */
    @Operation(summary = "添加Jijin",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @PostMapping
    public Result add(@RequestBody  @Parameter(name = "Jijin对象",required = true) Jijin jijin){
        try {
            // 格式化数据
            // 保留两位小数
            DecimalFormat df = new DecimalFormat("0.00");
            jijin.setBuyMoney(df.format(Float.parseFloat(jijin.getBuyMoney())));
            //调用JijinService实现添加Jijin
            jijinService.add(jijin);
            return new Result(true,StatusCode.OK,"添加成功");
        } catch (NumberFormatException e) {
            e.printStackTrace();
            return new Result(true,StatusCode.ERROR,"添加失败",e);
        }
    }


    /***
     * 根据ID查询Jijin数据
     * @param id
     * @return
     */
    @Operation(summary = "根据ID查询Jijin",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @Parameter(in = ParameterIn.PATH, name = "id", description = "ID", required = true)
    @GetMapping("/{id}")
    public Result<Jijin> findById(@PathVariable Integer id) {
        //调用JijinService实现根据ID查询Jijin
        Jijin jijin = jijinService.findById(id);
        return new Result<Jijin>(true, StatusCode.OK, "查询成功", jijin);
    }

    /***
     * 根据code查询最新估值
     * @param code
     * @return
     */
    @Operation(summary = "根据ID查询Jijin",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @Parameter(in = ParameterIn.PATH, name = "code", description = "code", required = true)
    @GetMapping("/newest/{code}")
    public Result<Object> findNewest(@PathVariable String code) {
        HttpResult httpResult = null;
        try {
            String url = JijinUrlUtil.creatUrl(code, 13);
            httpResult = JijinHttpUtil.sendGetReq(url);
            return new Result<Object>(true, StatusCode.OK, "查询最新估值成功", httpResult);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result<Object>(true, StatusCode.ERROR, "查询最新估值失败");
        }

    }


    /***
     * 根据code查询基金名称
     * @param code
     * @return
     */
    @Operation(summary = "根据ID查询Jijin",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @Parameter(in = ParameterIn.PATH, name = "code", description = "code", required = true)
    @GetMapping("/name/{code}")
    public Result<HttpResult> findName(@PathVariable String code) {
        HttpResult httpResult = null;
        try {
            String url = UrlUtil.creatUrl(code, 8);
            httpResult = HttpUtil.sendGetReq(url, null, "utf-8",null,null);
            return new Result<HttpResult>(true, StatusCode.OK, "查询最新估值成功", httpResult);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result<HttpResult>(true, StatusCode.ERROR, "查询最新估值失败");
        }

    }



    /***
     * 根据code查询Jijin数据及建议数据
     * @param code
     * @param model  建议模式（zy： 止盈  zs： 止损）
     * @return
     */
    @Operation(summary = "根据code查询Jijin数据及建议数据",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @Parameters({
            @Parameter(in = ParameterIn.PATH,name = "code", description = "code", required = true),
            @Parameter(in = ParameterIn.PATH,name = "model", description = "model", required = true)
    })
    @GetMapping("/{code}/{model}")
    public Result<List<Jijin>> findByCode(@PathVariable(value = "code") String code, @PathVariable(value = "model") String model) throws Exception {
        List<Jijin> list =  new ArrayList<>();
        try {
            if (code == null || model == null){
                return new Result(true, StatusCode.UNPOWER, "参数错误");
            }else {
                // 根据code查询已买入的基金
                Jijin jijin1 = new Jijin();
                jijin1.setCode(code);
                jijin1.setStatus(1);
                list = jijinService.findList(jijin1); // 已买入基金列表
                Float freeNumber =findFreeNumber(code).getData();  // 可赎回份额
                if (list != null && list.size() != 0){
                    String url = JijinUrlUtil.creatUrl(code, 13);
                    HttpResult httpResult = JijinHttpUtil.sendGetReq(url);
                    Float nav = httpResult.getGsz();  //获取当前净值
                    if ("zy".equalsIgnoreCase(model)){
                        // 止盈模式
                        for (Jijin jijin : list) {
                            if (nav > Float.parseFloat(jijin.getBuyPrice()) * 1.05  && freeNumber >= Float.parseFloat(jijin.getBuyNumber())){
                                jijin.setIsIdea(1);
                            }else {
                                jijin.setIsIdea(0);
                            }
                            jijin.setProfit((nav-Float.parseFloat(jijin.getBuyPrice()))*Float.parseFloat(jijin.getBuyNumber()));
                        }
                        return new Result<List<Jijin>>(true, StatusCode.OK, "止盈模式", list);
                    }else if("zs".equalsIgnoreCase(model)){
                        // 止损模式

                        Float profitMoney = 0F; // 盈利总额

                        List<Float> positive = new ArrayList<>(); // 盈利列表
                        List<Float> negative = new ArrayList<>(); // 亏损列表

                        // 将数据分类
                        for (Jijin jijin : list) {
                            jijin.setIsIdea(0);
                            if (Float.parseFloat(jijin.getBuyPrice()) <= nav){
                                positive.add(Float.parseFloat(jijin.getBuyPrice()));
                            }else {
                                negative.add(Float.parseFloat(jijin.getBuyPrice()));
                            }
                        }

                        boolean positive_flag = true; // 盈利资金是否全部走完标志

                        a:while (positive.size() > 0){
                            // 寻找盈利最大的基金
                            Float positive_number = Float.MAX_VALUE;
                            for (Float aFloat : positive) {
                                if (aFloat <= positive_number){}
                                positive_number = aFloat;
                            }

                            // 找到最大盈利基金数据
                            b:for (Jijin jijin : list) {
                                if (Float.parseFloat(jijin.getBuyPrice()) == positive_number){
                                    // 找到后先看可赎回资金够不够
                                    if (freeNumber >= Float.parseFloat(jijin.getBuyNumber())){
                                        freeNumber -= Float.parseFloat(jijin.getBuyNumber());
                                        Float positive_profit = Float.parseFloat(jijin.getBuyNumber()) * ( nav - Float.parseFloat(jijin.getBuyPrice())); // 盈利金额
                                        profitMoney += positive_profit;
                                        jijin.setIsIdea(1);
                                        // 剔除positive数据
                                        positive.remove(positive_number);
                                        continue a;
                                    }else {
                                        // 可赎回资金不够了 直接退出外层循环
                                        positive_flag = false;
                                        break a;
                                    }
                                }
                            }
                        }

                        // 判断盈利资金是否走完
                        if (positive_flag){
                            // 走完了
                            c:while (negative.size() > 0){
                                // 寻找亏损最大的基金
                                Float negative_number = 0F;
                                for (Float aFloat : negative) {
                                    if (aFloat >= negative_number){
                                        negative_number = aFloat;
                                    }
                                }

                                // 找到最大亏损基金数据
                                d:for (Jijin jijin : list) {
                                    if (Float.parseFloat(jijin.getBuyPrice()) == negative_number) {
                                        // 找到后先看可赎回资金够不够且盈利额是否够
                                        Float negative_profit = Float.parseFloat(jijin.getBuyNumber()) * (Float.parseFloat(jijin.getBuyPrice()) - nav); // 亏损金额
                                        if (freeNumber >= Float.parseFloat(jijin.getBuyNumber())&& profitMoney >= negative_profit) {
                                            freeNumber -= Float.parseFloat(jijin.getBuyNumber());
                                            profitMoney -= negative_profit;
                                            jijin.setIsIdea(1);
                                            // 剔除positive数据
                                            positive.remove(negative_number);
                                            continue c;
                                        } else {
                                            // 可赎回资金不够了或盈利抵消没了 直接退出外层循环
                                            break c;
                                        }
                                    }
                                }
                            }
                        }

                        // 没走完 直接返回数据
                        return new Result<List<Jijin>>(true, StatusCode.OK, "止损模式",list);
                    }
                }else {
                    return new Result(true, StatusCode.ERROR, "你已空仓");
                }
            }
        }catch (Exception e){
            e.printStackTrace();
            return new Result(true, StatusCode.ERROR, "服务器错误或参数错误");
        }

        return new Result<List<Jijin>>(true, StatusCode.OK, "止损模式",list);
    }


    /***
     * 查询Jijin列表数据
     * @return
     */
    @Operation(summary = "查询所有Jijin",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @GetMapping("/list/{model}")
    public Result<Object> findList(@PathVariable String model){
        try {
            HashMap<String, JijinList> mapList = new HashMap<>();
            HashMap<String, List<Jijin>> map = new HashMap<>();

            // 获取所有已确认并持有数据
            Jijin jijin = new Jijin();
            jijin.setStatus(1);
            List<Jijin> list = jijinService.findList(jijin);

            // 更新mySet 获取所有持有数据
            mySet = new HashSet<>();
            for (Jijin jj : list) {
                mySet.add(jj.getCode());
            }

            // 初始化map
            for (String ms : mySet) {
                map.put(ms, new ArrayList<Jijin>());
            }

            // 添加map数据
            for (Jijin jj : list) {
                map.get(jj.getCode()).add(jj);
            }

            // 填充mapList
            for (String s : map.keySet()) {
                JijinList jijinList = new JijinList();
                String code = map.get(s).get(0).getCode();
                String name = map.get(s).get(0).getName();
                Float sumMoney = 0F; // 所有金额
                JijinFreeNumber jijinFreeNumber = new JijinFreeNumber();
                jijinFreeNumber.setCode(code);
                List<JijinFreeNumber> freeList = jijinFreeNumberService.findList(jijinFreeNumber);
                Float freeNumber = findFreeNumber(code).getData();

                Float allNumber = 0F; // 所有份额

                for (Jijin jj : map.get(s)) {
                    sumMoney += Float.parseFloat(jj.getBuyMoney());
                    allNumber += Float.parseFloat( jj.getBuyNumber());
                }
//                DecimalFormat df = new DecimalFormat("0.00");
                // 格式化数据 保留两位小数
                jijinList.setCode(code);
//                jijinList.setAllNumber(Float.parseFloat(df.format(allNumber)));
                jijinList.setAllNumber(allNumber);
//                jijinList.setFreeNumber(Float.parseFloat(df.format(freeNumber)));
                jijinList.setFreeNumber(freeNumber);
                jijinList.setName(name);
//                jijinList.setSumMoney(Float.parseFloat(df.format(sumMoney)));
                jijinList.setSumMoney(sumMoney);

                // 计算建议操作总额
                Float ideasNumber = 0F;

                List<Jijin> ideas = (List<Jijin>)findByCode(code, model).getData();

                for (Jijin idea : ideas) {
                    if (idea.getIsIdea() == 1){
                        ideasNumber += Float.parseFloat(idea.getBuyNumber());
                    }
                }

                jijinList.setIdeasNumber(ideasNumber);

                mapList.put(name,jijinList);
            }

            return new Result<Object>(true, StatusCode.OK,"查询成功",mapList) ;
        }catch (Exception e){
            e.printStackTrace();
            return new Result<Object>(true, StatusCode.ERROR,"查询失败") ;
        }
    }

    /***
     * 查询可赎份额
     * @return
     */
    @Operation(summary = "查询可赎份额",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @GetMapping("/freeNumber/{code}")
    public Result<Float> findFreeNumber(@PathVariable String code){
        try {
            Float freeNumber = null;  // 可赎回份额
            JijinFreeNumber jijinFreeNumber = new JijinFreeNumber();
            jijinFreeNumber.setCode(code);
            List<JijinFreeNumber> jijinFreeNumberServiceList = jijinFreeNumberService.findList(jijinFreeNumber);
            if (jijinFreeNumberServiceList == null || jijinFreeNumberServiceList.size() == 0){
                // 没有该可赎份额记录
                jijinFreeNumber.setName(findName(code).getData().getName());
                jijinFreeNumber.setFreeNumber("0");
                jijinFreeNumberService.add(jijinFreeNumber);
                freeNumber = 0F;
            }else  {
                freeNumber = Float.parseFloat(jijinFreeNumberServiceList.get(0).getFreeNumber());
            }
            return new Result<Float>(true, StatusCode.OK,"查询可赎份额成功",freeNumber) ;
        }catch (Exception e){
            return new Result<Float>(true, StatusCode.ERROR,"查询可赎份额失败") ;
        }
    }


    /***
     * 查询执行中的数据
     * @return
     */
    @Operation(summary = "查询执行中的数据",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @GetMapping("/doing")
    public Result<List<Jijin>> findDoing(){
        try {
            List<Jijin> list = jijinService.findIsDoing();
//            List<Jijin> isNotFree = jijinService.findIsNotFree();
            return new Result<List<Jijin>>(true, StatusCode.OK,"查询成功",list) ;
        }catch (Exception e){
            e.printStackTrace();
            return new Result<List<Jijin>>(true, StatusCode.ERROR,"查询失败") ;
        }
    }


    /***
     * 查询执行完的数据
     * @return
     */
    @Operation(summary = "查询执行完的数据",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @GetMapping("/finish")
    public Result<List<Jijin>> findFinish(){
        try {
            List<Jijin> list = jijinService.findIsOver();
            return new Result<List<Jijin>>(true, StatusCode.OK,"查询成功",list) ;
        }catch (Exception e){
            e.printStackTrace();
            return new Result<List<Jijin>>(true, StatusCode.ERROR,"查询失败") ;
        }
    }


    /***
     * 查询Jijin全部数据
     * @return
     */
    @Operation(summary = "查询所有Jijin",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @GetMapping("/all")
    public Result<Object> findAll(){
        try {
            HashMap<String, List<Jijin>> map = new HashMap<>();

            // 获取所有已确认并持有数据
            Jijin jijin = new Jijin();
            jijin.setStatus(1);
            List<Jijin> list = jijinService.findList(jijin);

            // 更新mySet 获取所有持有数据
            mySet = new HashSet<>();
            for (Jijin jj : list) {
                // 格式化数据
                mySet.add(jj.getCode());
            }

            // 初始化map
            for (String ms : mySet) {
                map.put(ms, new ArrayList<Jijin>());
            }

            // 添加map数据
            for (Jijin jj : list) {
                map.get(jj.getCode()).add(jj);
            }

            return new Result<Object>(true, StatusCode.OK,"查询成功",map) ;
        }catch (Exception e){
            e.printStackTrace();
            return new Result<Object>(true, StatusCode.ERROR,"查询失败") ;
        }

    }



    /***
     * 查询Jijin菜单
     * @return
     */
    @Operation(summary = "查询所有Jijin",description = "所需权限：",security ={@SecurityRequirement(name ="Authorization")})
    @GetMapping("/menu")
    public Result<List> findMenu(){
        try {

            // 获取所有已确认并持有数据
            Jijin jijin = new Jijin();
            jijin.setStatus(1);
            List<Jijin> list = jijinService.findList(jijin);

            // 获取所有持有并去重
            Set<Map<String, String>> resultSet = new HashSet<>();
            for (Jijin jj : list) {
                Map<String, String> map = new HashMap<>();
                map.put(jj.getCode(),jj.getName());
                resultSet.add(map);
            }

            List resultList = new ArrayList();
            for (Map<String, String> mp : resultSet) {
                for (String s : mp.keySet()) {
                    JijinMenu jijinMenu = new JijinMenu();
                    jijinMenu.setCode(s);
                    jijinMenu.setName(mp.get(s));
                    resultList.add(jijinMenu);
                }
            }

            return new Result<List>(true, StatusCode.OK,"查询成功",resultList) ;
        }catch (Exception e){
            e.printStackTrace();
            return new Result<List>(true, StatusCode.ERROR,"查询失败") ;
        }
    }


    /**
     * list反转
     * @param list
     * @return
     */
    public List<Jijin> Listreverse(List<Jijin> list) {
        List<Jijin> resultList =  new ArrayList<Jijin>();

        while (list.size() > 0){
            resultList.add(list.get(list.size()-1));
            list.remove(list.get(list.size()-1));
        }

        return resultList;
    }


    /**
     * 根据list创建修改时间字符串
     * @param list
     * @return
     */
    public List<Jijin> listAddTimeStr(List<Jijin> list) {

        // 格式化数据
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (int i = 0; i < list.size(); i++) {
            Jijin jijin = list.get(i);
            jijin.setGmtCreateStr(format.format(jijin.getGmtCreate()));
            jijin.setGmtModifiedStr(format.format(jijin.getGmtModified()));
        }


        return list;
    }


}
